<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>法人股东信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body>
		<form id="cust_cst_corp_shr_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">股东类型</div>
                    <div class="field">
                        <select name="shrTypCd" id="shrTypCd" data-value=" " validate="{required:true, select: true}">
                             <option value=" " selected="selected">请选择</option>
                            <c:forEach items="${searchSelectShrTypCdList }" var="kv">
					 	    	<option value="${kv.key }">${kv.value }</option>
				   			</c:forEach>
                        </select>
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
               
                
                <div class="fieldBox col_50">
                    <div class="label">股东名称</div>
                    <div class="field">
                        <input name="shrNm" id="shrNm" type="text" class="ui-textbox" value="" validate="{required:true,maxlength:30}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">证件类型</div>
                    <div class="field">
	                     <select name="certTypCd" id="certTypCd" data-value=" ">
	                             <option value=" " selected="selected">请选择</option>
	                            <c:forEach items="${searchSelectCertTypCdList }" var="kv">
						 	    	<option value="${kv.key }">${kv.value }</option>
					   			</c:forEach>
	                     </select>
                     </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">证件号</div>
                    <div class="field">
                        <input name="certNo" id="certNo" type="text" class="ui-textbox" value="" validate="{maxlength:20}">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">出资情况</div>
                    <div class="field">
                        <input name="cntrAmt" id="cntrAmt" type="text" class="ui-textbox" value="" validate="{number:true}" onblur="countEquPropPct()">
                        <span class="requiredSymbol">万元</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">出资方式</div>
                    <div class="field">
	                     <%-- <select name="contrWay" id="contrWay" data-value=" ">
	                             <option value=" " selected="selected">请选择</option>
	                            <c:forEach items="${searchSelectContrWayList }" var="kv">
						 	    	<option value="${kv.key }">${kv.value }</option>
					   			</c:forEach>
	                     </select> --%>
	                     <input name="contrWay" id="contrWay" type="text" class="ui-textbox" value="">
                     </div>
                </div>
                <div class="fieldBox col_50">
                     <div class="label">出资日期</div>
                     <div class="field">
                        <input name="contrDt" id="contrDt" type="text" class="ui-datepicker" value="" >
                     </div>
                </div>
                <div class="fieldBox col_50">
                     <div class="label">出资占比(%)</div>
                     <div class="field">
                        <input name="equPropPct" id="equPropPct" type="text" class="ui-textbox" value="" readonly>
                     </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">备注</div>
                    <div class="field" style="width: 100%;">
                        <textarea name="shrRemark" id="shrRemark" rows="4" class="l-textarea" style="width:90%" validate="{maxlength:70}"></textarea>
                    </div>
                </div>
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
		              <input name="ccsId" id="ccsId" type="text" class="ui-textbox" value="${ccsId}">
		          </div>
		        </div>
            </div>
        </form>
	<script>
		$(function() {
		   $("#cust_cst_corp_shr_form").ligerForm({
                validate: true
           });
	       initData();
		});
		
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("cust_cst_corp_shr_form");
            if (!ligerForm.valid()) {
            	UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            data["contrDt"] = $("#contrDt").val();
            var ccsId = $("#ccsId").val();
            var _url = '<%=path%>/customer/cstcorpshr/add.do';
            if(ccsId != ""){
            	_url = '<%=path%>/customer/cstcorpshr/modify.do';
            	data["id"]= ccsId;
            }

            //设置客户ID
            var cstId = $("#cstId").val();
            data["cstId"]= cstId;
            AjaxUtils.ajaxPost(_url, data, function(msg){
            	if(msg.success == 1){
	   				 UIUtils.alertSuccess(msg.info);
	   				 parent.cstCorpShrGrid.setParm("cstId",cstId);
	   				 parent.cstCorpShrGrid.reload();
	   				 frameElement.dialog.close();
	   			 }else{
	   				 UIUtils.alertError(msg.info);
	   			 }
            },true);
		}
		
		function initData(){
			var ccsId = $("#ccsId").val();
	    	if(!ccsId)return;
	    	var _url = '<%=path%>/customer/cstcorpshr/getById.do';
	    	AjaxUtils.ajaxGet(_url, {id:ccsId}, function(msg){
	    		if(msg.success == 1){
	   				 setData(msg.data);//设置数据
	   			 }else{
	   				UIUtils.alertError(msg.info);
	   			 }
	    	},true);
    	}
		
		//设置页面数据
	    function setData(data){
	    	var form = new liger.get("cust_cst_corp_shr_form");
	    	if(StringUtils.isNotEmpty(data.contrDt)){
	    		var date = new Date(data.contrDt);
		    	var dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
	    		$("#contrDt").val(dateStr);
	    	}
	    	
	    	form.setData({
	    		shrTypCd:data.shrTypCd,
	    		shrNm:data.shrNm,
	    		certTypCd:data.certTypCd,
	    		certNo:data.certNo,
	    		cntrAmt:data.cntrAmt,
	    		contrWay:data.contrWay,
	    		equPropPct:data.equPropPct,
	    		shrRemark:data.shrRemark
	    	});
		};
		//计算出资占比
		function countEquPropPct(){
			var cntrAmt = $("#cntrAmt").val();
			if(!cntrAmt){
				$("#equPropPct").val("");
			}
			var cstId = $("#cstId").val();
			var _url = '<%=path%>/customer/cstcorpshr/countEquPropPct.do';
			AjaxUtils.ajaxPost(_url, {cntrAmt:cntrAmt,cstId:cstId}, function(msg){
				 if(msg.success == 1){
    				 if(StringUtils.isNotEmpty(msg.data)){
	    				 $("#equPropPct").val(msg.data);
    				 }
    			 }else{
    				 UIUtils.alertError(msg.info);
    			 }
			},true);
		}
	</script>
</body>
</html>